// internal/planner/physical/plan_nodes.go
package physical

import (
    "fmt"
    "NumberBase/internal/planner/types"
)

// TableScan 物理表扫描
type TableScan struct {
    TableName string
    SchemaRef *types.Schema
    // 物理属性
    UseIndex  string
    EstimatedRows int
    costVal   float64
}

func (s *TableScan) Type() types.PlanType {
    return types.PlanPhysicalScan
}

func (s *TableScan) Children() []types.PhysicalPlan {
    return nil
}

func (s *TableScan) Schema() *types.Schema {
    return s.SchemaRef
}

func (s *TableScan) String() string {
    indexInfo := ""
    if s.UseIndex != "" {
        indexInfo = fmt.Sprintf(", index: %s", s.UseIndex)
    }
    return fmt.Sprintf("PhysicalTableScan: %s%s, rows: %d", 
                     s.TableName, indexInfo, s.EstimatedRows)
}

func (s *TableScan) Cost() float64 {
    return s.costVal
}

// Filter 物理过滤
type Filter struct {
    Input     types.PhysicalPlan
    Condition types.Expression
    costVal   float64
}

func (f *Filter) Type() types.PlanType {
    return types.PlanPhysicalFilter
}

func (f *Filter) Children() []types.PhysicalPlan {
    return []types.PhysicalPlan{f.Input}
}

func (f *Filter) Schema() *types.Schema {
    return f.Input.Schema()
}

func (f *Filter) String() string {
    return fmt.Sprintf("PhysicalFilter: %s\n  %s", 
                     f.Condition.String(), f.Input.String())
}

func (f *Filter) Cost() float64 {
    return f.costVal
}

// Projection 物理投影
type Projection struct {
    Input       types.PhysicalPlan
    Expressions []types.Expression
    OutputSchema *types.Schema
    costVal     float64
}

func (p *Projection) Children() []types.PhysicalPlan {
    return []types.PhysicalPlan{p.Input}
}

func (p *Projection) Cost() float64 {
    return p.costVal
}

func (p *Projection) Schema() *types.Schema {
    return p.OutputSchema
}

func (p *Projection) String() string {
	return fmt.Sprintf("PhysicalProjection: %s", p.Expressions)
}

// Add to physical/plan_nodes.go
func (p *Projection) Type() types.PlanType {
    return types.PlanPhysicalProject
}